﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <!-- Documenting T:NAnt.Contrib.Tasks.SqlTask-->
  <head>
    <meta http-equiv="Content-Language" content="en-ca" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="../style.css" />
    <title>&lt;sql&gt; Task</title>
  </head>
  <body>
    <table width="100%" border="0" cellspacing="0" cellpadding="2" class="NavBar">
      <tr>
        <td class="NavBar-Cell">
          <a href="">
            <b>NAntContrib</b>
          </a>
          <img alt="-&gt;" src="../images/arrow.gif" />
          <a href="../index.html">Help</a>
          <img alt="-&gt;" src="../images/arrow.gif" />
          <a href="../tasks/index.html">Task Reference</a>
          <img alt="-&gt;" src="../images/arrow.gif" /> &lt;sql&gt;</td>
        <td class="NavBar-Cell" align="right">
                        v0.85</td>
      </tr>
    </table>
    <h1>&lt;sql&gt;</h1>
    <p> A task to execute arbitrary SQL statements against a OLEDB data source. </p> You can specify a set of sql statements inside the sql element, or execute them from a text file that contains them. You can also choose to execute the statements in a single batch, or execute them one by one (even inside a transaction, if you want to). <h3>Parameters</h3><div class="table"><table><tr><th>Attribute</th><th style="text-align: center;">Type</th><th>Description</th><th style="text-align: center;">Required</th></tr><tr><td valign="top" class="required">connstring</td><td style="text-align: center;">string</td><td> Connection string used to access database. This should be an OleDB connection string. </td><td style="text-align: center;">True</td></tr><tr><td valign="top" class="required">delimiter</td><td style="text-align: center;">string</td><td> String that separates statements from one another. </td><td style="text-align: center;">True</td></tr><tr><td valign="top" class="required">delimstyle</td><td style="text-align: center;"><a href="../enums/NAnt.Contrib.Util.DelimiterStyle.html">DelimiterStyle</a></td><td> Kind of delimiter used. Allowed values are Normal or Line. </td><td style="text-align: center;">True</td></tr><tr><td valign="top">append</td><td style="text-align: center;">bool</td><td> Whether output should be appended to or overwrite an existing file. The default is <b>false</b>. </td><td style="text-align: center;">False</td></tr><tr><td valign="top">batch</td><td style="text-align: center;">bool</td><td> If true, the statements will be executed as a single batch. If false, they will be executed one by one. Default is true. </td><td style="text-align: center;">False</td></tr><tr><td valign="top">cmdtimeout</td><td style="text-align: center;">int</td><td> Command timeout to use when creating commands. </td><td style="text-align: center;">False</td></tr><tr><td valign="top">encoding</td><td style="text-align: center;"><a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemTextEncodingClassTopic.asp">Encoding</a></td><td> The encoding of the files containing SQL statements. The default is the system's current ANSI code page. </td><td style="text-align: center;">False</td></tr><tr><td valign="top">expandprops</td><td style="text-align: center;">bool</td><td> If true, the any nant-style properties on the sql will be expanded before execution. Default is true. </td><td style="text-align: center;">False</td></tr><tr><td valign="top">output</td><td style="text-align: center;">string</td><td> If set, the results from the statements will be output to the specified file. </td><td style="text-align: center;">False</td></tr><tr><td valign="top">print</td><td style="text-align: center;">bool</td><td> If set to true, results from the statements will be output to the build log. </td><td style="text-align: center;">False</td></tr><tr><td valign="top">quotechar</td><td style="text-align: center;">string</td><td> The character(s) to surround result columns with when printing, the default is an empty string. </td><td style="text-align: center;">False</td></tr><tr><td valign="top">showheaders</td><td style="text-align: center;">bool</td><td> If set to <b>true</b>, prints headers for result sets. The default is <b>true</b>. </td><td style="text-align: center;">False</td></tr><tr><td valign="top">source</td><td style="text-align: center;">string</td><td> File where the sql statements are defined. </td><td style="text-align: center;">False</td></tr><tr><td valign="top">transaction</td><td style="text-align: center;">bool</td><td> If set to <b>true</b>, all statements will be executed within a single transaction. The default is <b>true</b>. </td><td style="text-align: center;">False</td></tr><tr><td valign="top">failonerror</td><td style="text-align: center;">bool</td><td> Determines if task failure stops the build, or is just reported. The default is <b>true</b>. </td><td style="text-align: center;">False</td></tr><tr><td valign="top">if</td><td style="text-align: center;">bool</td><td> If <b>true</b> then the task will be executed; otherwise, skipped. The default is <b>true</b>. </td><td style="text-align: center;">False</td></tr><tr><td valign="top">unless</td><td style="text-align: center;">bool</td><td> Opposite of <code>if</code>. If <b>false</b> then the task will be executed; otherwise, skipped. The default is <b>false</b>. </td><td style="text-align: center;">False</td></tr><tr><td valign="top">verbose</td><td style="text-align: center;">bool</td><td> Determines whether the task should report detailed build log messages. The default is <b>false</b>. </td><td style="text-align: center;">False</td></tr></table></div><h3>Examples</h3><ul class="examples"><li><p> Execute a set of statements inside a transaction. </p><pre class="code">
&lt;sql
    connstring="Provider=SQLOLEDB;Data Source=localhost; Initial Catalog=Pruebas; Integrated Security=SSPI"
    transaction="true"
    delimiter=";"
    delimstyle="Normal"
&gt;
    INSERT INTO jobs (job_desc, min_lvl, max_lvl) VALUES('My Job', 22, 45);
    INSERT INTO jobs (job_desc, min_lvl, max_lvl) VALUES('Other Job', 09, 43);
    SELECT * FROM jobs;
&lt;/sql&gt;
    </pre></li><li><p> Execute a set of statements from a file and write all query results to a file. </p><pre class="code">
&lt;sql
    connstring="Provider=SQLOLEDB;Data Source=localhost; Initial Catalog=Pruebas; Integrated Security=SSPI"
    transaction="true"
    delimiter=";"
    delimstyle="Normal"
    print="true"
    source="sql.txt"
    output="${outputdir}/results.txt"
/&gt;
    </pre></li><li><p> Execute a SQL script generated by SQL Server Enterprise Manager. </p><pre class="code">
&lt;sql
    connstring="Provider=SQLOLEDB;Data Source=localhost; Initial Catalog=Pruebas; Integrated Security=SSPI"
    transaction="true"
    delimiter="GO"
    delimstyle="Line"
    print="true"
    source="pubs.xml"
    batch="false"
    output="${outputdir}/results.txt"
/&gt;
    </pre></li></ul><h3>Requirements</h3><div style="margin-left: 20px;"><b>Assembly:</b> NAnt.Contrib.Tasks (0.85.2479.0)
            </div></body>
</html>